package com.sansui.blog.controller;

import com.sansui.blog.pojo.Blog;
import com.sansui.blog.pojo.SysConfig;
import com.sansui.blog.service.ArchiveService;
import com.sansui.blog.service.BlogService;
import com.sansui.blog.service.SysInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * @name: BlogArchiveController
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-05-25 22:21
 **/
@RestController
public class BlogArchiveController {

    @Autowired
    private ArchiveService archiveService;

    @Autowired
    private BlogService blogService;

    @Autowired
    private SysInfoService sysInfoService;

    @RequestMapping(value = {"/archives"})
    public ModelAndView typeIndex(ModelAndView mv){
        Map<String, List<Blog>> archiveInfo = archiveService.getArchiveBlog();
        Map<String, Object> data = blogService.countBlogInfo();
        SysConfig sysConfig = sysInfoService.getSysSetting();

        mv.setViewName("theme/"+ sysConfig.getThemeName() +"/archives");
        mv.addObject("countblog",data.get("countblog"));
        mv.addObject("archiveInfo",archiveInfo);
        mv.addObject("webname",sysConfig.getWebname());
        return mv;
    }



}
